﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.woodsoft.core;
using EQ1.Elements;
using com.woodsoft.core.Files;
using EQ1.Objects;

namespace EQ1.Controls {
  public class TileLayoutBox : LayoutBox , IUIElement<TileLayoutBox> {
    public TileLayoutBox ( UIDocument doc , string name )
      : base( doc , name ) {
      this.HorizontalFirst = true;
      this.AnchorToTop = true;
      this.AnchorToLeft = true;
      this.SecondarySpacing = 5;
      this.FirstPieceTemplate = false;
      this.SnapToChildren = false;
    }
    public TileLayoutBox ( UIDocument doc )
      : this( doc , "TileLayoutBox" ) {
    }

    #region IUIElement<TileLayoutBox> Members

    public void Validate ( TileLayoutBox val , string name ) {
      UIClass par = ( UIClass ) this.ParentNode;

      if( val.LocalName != name ) {
        TileLayoutBox el = new TileLayoutBox( ( UIDocument ) val.OwnerDocument , name );
        el.Copy( val );
        val = el;
      }

      if( par.GetElement( name ) != null )
        par.RemoveElement( name );

      par.AppendChild( val );
    }

    public void Copy ( TileLayoutBox val ) {
      base.Copy( val );

      this.HorizontalFirst = val.HorizontalFirst;
      this.AnchorToTop = val.AnchorToTop;
      this.AnchorToLeft = val.AnchorToLeft;
      this.SecondarySpacing = val.SecondarySpacing;
      this.FirstPieceTemplate = val.FirstPieceTemplate;
      this.SnapToChildren = val.SnapToChildren;
    }

    #endregion

    public bool HorizontalFirst {
      get {
        return bool.Parse( this.GetElement( "HorizontalFirst" ).InnerText );
      }
      set {
        this.Validate( "HorizontalFirst" , value.ToString() );
      }
    }
    public bool AnchorToTop {
      get {
        return bool.Parse( this.GetElement( "AnchorToTop" ).InnerText );
      }
      set {
        this.Validate( "AnchorToTop" , value.ToString() );
      }
    }
    public bool AnchorToLeft {
      get {
        return bool.Parse( this.GetElement( "AnchorToLeft" ).InnerText );
      }
      set {
        this.Validate( "AnchorToLeft" , value.ToString() );
      }
    }
    public int SecondarySpacing {
      get {
        return int.Parse( this.GetElement( "SecondarySpacing" ).InnerText );
      }
      set {
        this.Validate( "SecondarySpacing" , value.ToString() );
      }
    }
    public bool FirstPieceTemplate {
      get {
        return bool.Parse( this.GetElement( "FirstPieceTemplate" ).InnerText );
      }
      set {
        this.Validate( "FirstPieceTemplate" , value.ToString() );
      }
    }
    public bool SnapToChildren {
      get {
        return bool.Parse( this.GetElement( "SnapToChildren" ).InnerText );
      }
      set {
        this.Validate( "SnapToChildren" , value.ToString() );
      }
    }
  }
}
